From 2501ac7b71b29dd9bb07d7e06c8aab168714b671 Mon Sep 17 00:00:00 2001 From: robertl Date: Mon, 31 Mar 2008 02:51:05 +0000 Subject: [PATCH] Don't hose if we replace a string with a string that's a supserset of the origin (e.g. in vcf if we replace ; with \\;). --- util.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/util.c b/util.c index d76b7ea3b..17807097f 100644 --- a/util.c +++ b/util.c @@ -1104,10 +1104,14 @@ char * gstrsub(const char *s, const char *search, const char *replace) { char *o = xstrdup(s); - - while (strstr(o, search)) { + char *tsearch = o; + // The tsearch silliness here is in case we decide to replace a string + // with a string that's a superset of that string. Replacing ";" + // with "\\;" in the vcf writer is our problem child. + while ((tsearch = strstr(tsearch, search))) { char *oo = o; o = strsub(o, search, replace); + tsearch = tsearch + strlen(replace); xfree(oo); } -- 2.30.2